home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / qbbs / qktmbps.zip / QKTMBPS.PAS < prev   
Pascal/Delphi Source File  |  1990-08-16  |  7KB  |  277 lines

  1. Program QkTmBPS;
  2.  
  3. Uses Dos, OpCRT, OpString, OpDate;
  4.  
  5. Type
  6.  
  7.   CommandRec = record
  8.     Baud     : string[4];
  9.     Day      : string[4];
  10.     STime    : Time;
  11.     ETime    : Time;
  12.   end;
  13.  
  14.   EventRec = record
  15.     Tag      : string[15];
  16.     Commands : array[1..10] of CommandRec;
  17.   end;
  18.  
  19. var
  20.   EventOK  : boolean;
  21.   x, y, TagNo : byte;
  22.   sTemp    : string;
  23.   F        : Text;
  24.   ThisBaud : string[4];
  25.   ThisDay  : DayType;
  26.   ThisTime : Time;
  27.   ThisTag  : string[15];
  28.   Tags     : array[1..10] of EventRec;
  29.   TagFile  : File of EventRec;
  30.   PrmInfo, EvtInfo : SearchRec;
  31.  
  32. procedure CheckCommandLine;
  33. begin
  34.   if ParamCount <> 1 then
  35.   begin
  36.     writeln('Syntax:  QkTmBPS Tag_Line');
  37.     Halt;
  38.   end;
  39.   ThisTag := StUpCase(ParamStr(1));
  40. end;
  41.  
  42. procedure Initialize;
  43. begin
  44.   EventOK  := false;
  45.   ThisBaud := '';
  46.   ThisDay  := DayOfWeek(Today);
  47.   ThisTime := CurrentTime;
  48.   for x := 1 to 10 do
  49.   begin
  50.     Tags[x].Tag := '';
  51.     for y := 1 to 10 do
  52.     begin
  53.       Tags[x].Commands[y].Baud  := '';
  54.       Tags[x].Commands[y].Day   := '';
  55.       Tags[x].Commands[y].STime := 0;
  56.       Tags[x].Commands[y].ETime := 0;
  57.     end;
  58.   end;
  59. end;
  60.  
  61. procedure WritePrmFile;
  62. var
  63.   Begun          : boolean;
  64.   TagLine : byte;
  65.   sStart, sEnd   : DateString;
  66. begin
  67.   writeln;
  68.   writeln('Reading QkTmBPS.Evt -> Compiling QkTmBPS.Prm');
  69.   assign(F, 'QkTmBPS.Evt');
  70.   {$I-}
  71.   reset(F);
  72.   {$I+}
  73.   if IOResult <> 0 then
  74.   begin
  75.     writeln('Could NOT find QkTmBPS.Evt - Event Control File!');
  76.     Halt;
  77.   end;
  78.   assign(TagFile, 'QkTmBPS.Prm');
  79.   rewrite(TagFile);
  80.   TagNo := 1; TagLine := 0; Begun := false;
  81.   while (TagNo <= 10) AND NOT EOF(F) do
  82.   begin
  83.     readln(F, sTemp);
  84.     if (sTemp <> '') AND (sTemp[1] <> ';') then
  85.     begin
  86.       sTemp := StUpCase(sTemp);
  87.       if Begun then
  88.       begin
  89.         if sTemp <> 'END_DEF' then
  90.         begin
  91.           inc(TagLine);
  92.           if TagLine <= 10 then
  93.           begin
  94.             Tags[TagNo].Commands[TagLine].Baud  := ExtractWord(1, sTemp, [' ']);
  95.             Tags[TagNo].Commands[TagLine].Day   := ExtractWord(2, sTemp, [' ']);
  96.             sStart := ExtractWord(3, sTemp, [' ']);
  97.             sEnd   := ExtractWord(4, sTemp, [' ']);
  98.             Tags[TagNo].Commands[TagLine].STime := TimeStringToTime('hh:mm', sStart);
  99.             Tags[TagNo].Commands[TagLine].ETime := TimeStringToTime('hh:mm', sEnd);
  100.           end;
  101.         end
  102.         else
  103.         begin
  104.           Begun := false;
  105.           TagLine := 0;
  106.           write(TagFile, Tags[TagNo]);
  107.           inc(TagNo);
  108.         end;
  109.       end
  110.       else
  111.         if sTemp = 'BEGIN_DEF' then
  112.         begin
  113.           Begun := true;
  114.           readln(F, sTemp);
  115.           sTemp := Trim(sTemp);
  116.           sTemp := StUpCase(sTemp);
  117.           Tags[TagNo].Tag := sTemp;
  118.         end;
  119.     end;
  120.   end;
  121.   SetFTime(TagFile, EvtInfo.Time);
  122.   close(F);
  123.   close(TagFile);
  124.   writeln('Done.');
  125. end;
  126.  
  127. procedure CheckPrmFile;
  128. begin
  129.   FindFirst('QkTmBPS.Evt', AnyFile, EvtInfo);
  130.   if DosError = 0 then
  131.   begin
  132.     FindFirst('QkTmBPS.Prm', AnyFile, PrmInfo);
  133.     if DosError <> 0 then WritePrmFile
  134.     else
  135.       if (PrmInfo.Time <> EvtInfo.Time) then WritePrmFile;
  136.   end
  137.   else
  138.   begin
  139.     writeln('Could NOT find QkTmBPS.Evt - Event Control File!');
  140.     Halt;
  141.   end;
  142. end;
  143.  
  144. procedure ReadPrmFile;
  145. begin
  146.   assign(TagFile, 'QkTmBPS.Prm');
  147.   {$I-}
  148.   reset(TagFile);
  149.   {$I+}
  150.   if IOResult <> 0 then
  151.   begin
  152.     writeln('Could NOT find QkTmBPS.Prm - Event Parameters File!');
  153.     Halt;
  154.   end;
  155.   TagNo := 0;
  156.   while (TagNo < 10) AND NOT EOF(TagFile) do
  157.   begin
  158.     inc(TagNo);
  159.     read(TagFile, Tags[TagNo]);
  160.   end;
  161.   close(TagFile);
  162. end;
  163.  
  164. procedure ReadDorInfo;
  165. begin
  166.   assign(F, 'DorInfo1.Def');
  167.   {$I-}
  168.   reset(F);
  169.   {$I+}
  170.   if IOResult <> 0 then
  171.   begin
  172.     writeln('Could NOT find DorInfo1.Def File!');
  173.     Halt;
  174.   end;
  175.   for x := 1 to 4 do ReadLn(F);
  176.   ReadLn(F, sTemp);
  177.   close(F);
  178.   ThisBaud := ExtractWord(1, sTemp, [' ']);
  179. end;
  180.  
  181. function CheckTime(ThisTime, StarT, EndT : Time) : boolean;
  182. begin
  183.   CheckTime := (ThisTime >= StarT) AND (ThisTime <= EndT);
  184. end;
  185.  
  186. procedure ExitWithErrorLevel;
  187. begin
  188.   for x := 1 to 10 do
  189.   begin
  190.     if ThisTag = Tags[x].Tag then
  191.     begin
  192.       for y := 1 to 10 do
  193.       begin
  194.         with Tags[x].Commands[y] do
  195.         begin
  196.           if Baud = ThisBaud then
  197.           begin
  198.  
  199.             if Day = 'ALL' then
  200.               if CheckTime(ThisTime, STime, ETime) then Halt(0);
  201.  
  202.             if Day = 'WK' then
  203.               case ThisDay of
  204.                 Sunday, Monday, Tuesday,
  205.                 Wednesday, Thursday, Friday :
  206.                   if CheckTime(ThisTime, STime, ETime) then Halt(0);
  207.               end;
  208.  
  209.             if Day = 'WKEND' then
  210.               case ThisDay of
  211.                 Saturday, Sunday : if CheckTime(ThisTime, STime, ETime) then
  212.                   Halt(0);
  213.               end;
  214.  
  215.             if Day = 'MON' then
  216.               if (ThisDay = Monday) AND
  217.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  218.  
  219.             if Day = 'TUE' then
  220.               if (ThisDay = Tuesday) AND
  221.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  222.  
  223.             if Day = 'WED' then
  224.               if (ThisDay = Wednesday) AND
  225.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  226.  
  227.             if Day = 'THU' then
  228.               if (ThisDay = Thursday) AND
  229.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  230.  
  231.             if Day = 'FRI' then
  232.               if (ThisDay = Friday) AND
  233.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  234.  
  235.             if Day = 'SAT' then
  236.               if (ThisDay = Saturday) AND
  237.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  238.  
  239.             if Day = 'SUN' then
  240.               if (ThisDay = Sunday) AND
  241.                  CheckTime(ThisTime, STime, ETime) then Halt(0);
  242.           end;
  243.         end;
  244.       end;
  245.     end;
  246.   end;
  247.   Halt(1);
  248. end;
  249.  
  250. begin
  251.   CheckCommandLine;
  252.   Initialize;
  253.   CheckPrmFile;
  254.   ReadPrmFile;
  255.   ReadDorInfo;
  256.   ExitWithErrorLevel;
  257.  
  258. {$IFDEF DEBUG}
  259.   for x := 1 to 10 do
  260.   begin
  261.     ClrScr;
  262.     writeln('Tag # ',x,'   Current Baud Rate: ', ThisBaud);
  263.     writeln('Tag Name: ', Tags[x].Tag);
  264.     writeln('Commands: ');
  265.     for y := 1 to 10 do
  266.     begin
  267.       write(Tags[x].Commands[y].Baud   , '  ');
  268.       write(Tags[x].Commands[y].Day    , '  ');
  269.       write(Tags[x].Commands[y].STime  , '  ');
  270.       writeln(Tags[x].Commands[y].ETime, '  ');
  271.     end;
  272.     readln;
  273.   end;
  274. {$ENDIF}
  275. end.
  276.  
  277.